package br.com.brands.application.ics.facade;

import br.com.brands.application.ics.beans.CategoryBeans;
import br.com.brands.application.ics.delegate.CategoryDelegate;
import java.util.List;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;

/**
 * Session Bean implementation class CategoryFacadeBean
 */
@Stateless(name = "CategoryFacadeBean", mappedName = "CategoryFacadeBean")
public class CategoryFacadeBean implements CategoryFacadeBeanLocal {

    private static final Logger log = Logger.getLogger("br.com.brands.application.ics.facade.CategoryFacadeBean");

    /**
     * Default constructor.
     */
    public CategoryFacadeBean() {
        log.log(Level.INFO, "Loading CategoryFacadeBean - EJB Facade Layer Level");
    }

    @Override
    public CategoryBeans save(CategoryBeans category) throws EJBException {

        CategoryBeans objRef = null;

        try {
            objRef = CategoryDelegate.getInstance().save(category);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }

    @Override
    public CategoryBeans saveOrUpdate(CategoryBeans category) throws EJBException {

        CategoryBeans objRef = null;

        try {
            objRef = CategoryDelegate.getInstance().saveOrUpdate(category);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }

    @Override
    public CategoryBeans delete(CategoryBeans category) throws EJBException {

        CategoryBeans objRef = null;

        try {
            objRef = CategoryDelegate.getInstance().delete(category);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }

    @Override
    public CategoryBeans findByID(CategoryBeans category, Long id, boolean lock)
            throws EJBException {

        CategoryBeans objRef = null;

        try {
            objRef = CategoryDelegate.getInstance().findByID(category, id, lock);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }

    @Override
    public List<CategoryBeans> findAll(CategoryBeans category)
            throws EJBException {

        List<CategoryBeans> list = null;

        try {
            list = CategoryDelegate.getInstance().findAll(category);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return list;
    }
}
